function [Data, elapsed] = SSVFile2Timetable(dataset, dataLines)
%IMPORTFILE Import data from a text file
%  HIMU1 = IMPORTFILE(FILENAME) reads data from text file FILENAME for
%  the default selection.  Returns the data as a table.
%
%  HIMU1 = IMPORTFILE(FILE, DATALINES) reads data for the specified row
%  interval(s) of text file FILENAME. Specify DATALINES as a positive
%  scalar integer or a N-by-2 array of positive scalar integers for
%  dis-contiguous row intervals.
%
%  Example:
%  HIMU1 = importfile("/home/vaningen/MEGAsync/MSc Sensor Fusion Thesis/Datasets/HIMU-2020-03-24_18-58-04.csv", [5, Inf]);
%
%  See also READTABLE.
%
% Auto-generated by MATLAB on 25-Mar-2020 09:54:39

%% Input handling

% If dataLines is not specified, define defaults
if nargin < 2
    dataLines = [5, Inf];
end
file = dataset.file;
dataSetProp = dataset.dataSetProp;
file_path = strcat(file.directory, file.name);

%% Setup the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 4);

% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = " ";

opts.VariableNames = ['elapsed', dataSetProp.time_var_name, dataSetProp.column_names];

opts.VariableTypes = repmat("double",[1 length(opts.VariableNames)]);

% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";

% Import the data
Data = readtable(file_path, opts);
Data = Data(:,2:end);

% remove first two rows
Data = Data(3:end,:);

% find elapsed time and transform from milliseconds to seconds
elapsed = Data.Time(:);
milli2sec = elapsed.*dataSetProp.time_units;
Data.Time = seconds(milli2sec);
Data = table2timetable(Data);
Data = unique(Data);

% HIMU app specific, first accelerometer sample is zero, this needs to be removed

% if Data(1,2) == 0 && Data(1,3) == 0 && Data(1,4) == 0
%     Data(1,:) = [];
% end

end